package com.service;

import cn.hutool.log.Log;
import com.mapper.C_inforDao;
import com.mapper.C_userDao;
import com.util.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class C_userService {
    @Resource
    private C_userDao c_userDao;
    @Resource
    private C_inforDao c_inforDao;

    public Result<?> login(C_user c_user) {
        System.out.println(c_user);
        C_user c = c_userDao.selectByAccount(c_user);
        System.out.println(c);
        Result result=new Result();
        if (c == null) {
            Result r=result.error(result,"0","用户名或者密码错误");
            return r;
        } else {
            if (c_user.getcPassword().equals(c.getcPassword()) ) {
                Result r=result.success(c.getpId(),result);
                return r;
            } else {
                Result r=result.error(result,"0","用户名或者密码错误");
                return r;
            }
        }
    }
    public Result<?> register(C_register c_register) {
        C_user c_user=new C_user();
        c_user.setCAccount(c_register.getcAccount());
        c_user.setcPassword(c_register.getcPassword());
        c_user.setpId(c_register.getpId());
        C_infor c_infor=new C_infor();
        c_infor.setcAccount(c_register.getcAccount());
        c_infor.setcName(c_register.getcName());
        c_infor.setRepresentative(c_register.getRepresentative());
        c_infor.setSignature(c_register.getSignature());
        c_infor.setClient(c_register.getClient());
        c_infor.setIndustry(c_register.getIndustry());
        c_infor.setNature(c_register.getNature());
        c_infor.setLevel(c_register.getLevel());
        c_infor.setpId(c_register.getpId());
        C_user c=c_userDao.selectByAccount(c_user);
        C_user c2=c_userDao.selectByP_id(c_user);
        Result result=new Result();
        if(c!=null){
            Result r=result.error(result,"-1","该社会信用代码已被注册");
            return r;
        }else if(c2!=null){
            Result r=result.error(result,"-2","法定代表人重复");
            return r;
        }else {
            c_userDao.insert(c_user);
            c_inforDao.insert(c_infor);
            Result r=result.success(result);
            return r;
        }
    }
    public Result<?> updatePassword(C_user c_user){
        Result result=new Result();
        c_userDao.updatePassword(c_user);
        Result r=result.success(result);
        return r;
    }
}
